<?php

/**
 * @author kevin
 * @date 2016-01-16 14:00:00
 * @desc 首页广告
 */

if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}
$version = '1.0';   //版本号

if ($_POST['api_version'] != $version)      //网店的接口版本低
{
	api_err('0x008', 'a low version api');
}
//问题分类
if($_POST['st'] == 'list'){
	$data = article_categories_child(5);
}
//问题列表
if($_POST['st'] == 'question'){
	$cat_id = isset($_POST['cat_id'])?intval(abs($_POST['cat_id'])):0;
	$page = isset($_POST['page'])?intval(abs($_POST['page'])):1;
	$size = abs(intval($_POST['size']));
	$size = ($size > 0 && $size < SIZE_MAX)?$size:SIZE_VALUE;
	$keywords = isset($_POST['keywords'])?trim($_POST['keywords']):'';
	if(empty($cat_id)){
		api_err('0x008', 'param cat_id is error');
	}
	$count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " .$ecs->table('article').
                                " WHERE is_open = 1 and ".get_article_children($cat_id)." ORDER BY article_id DESC");
	$pager = get_pager('user.php', array('act' => 'collection_list'), $count, $page, $size);
	$data['list'] = get_cat_articlesv1($cat_id, $page, $size ,$keywords);
	$data['page'] = get_app_pager($pager);
}
//热门问题列表
if($_POST['st'] == 'hot'){
	$data = get_class_list_articles(0,1,5);
}
//st参数错误
if(!isset($data)){
	api_err('0x008');
}
//返回数据
data_back($data, '', RETURN_TYPE);
